/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-10-05
 * Time:10:00
 */
public class Test {
    public static MySingleLink.LinkedList mergeTwoLists(MySingleLink.LinkedList head1,MySingleLink.LinkedList head2){
        MySingleLink.LinkedList newHead=new MySingleLink.LinkedList(-1);//随便给个值无所谓的
        MySingleLink.LinkedList temp=newHead;
        if(head1.val<head2.val){
            temp.next=head1;
            head1=head1.next;
            temp=temp.next;
        }else{
            temp.next=head2;
            head2=head2.next;
            temp=temp.next;
        }
        return newHead;

    }
    //输入两个链表，找出它们的第一个公共结点
    public MySingleLink.LinkedList getIntersectionNode(MySingleLink.LinkedList head1, MySingleLink.LinkedList head2){
        //计算两个链表的长度，并比较谁的长度更长
        return null;
    }
    public static void createCut(MySingleLink.LinkedList head){
        ;
    }
    public static boolean hasCycle(MySingleLink.LinkedList head){
        MySingleLink.LinkedList fast;
        MySingleLink.LinkedList slow;
        fast=slow=head;
        if(head==null){
            return false;
        }
        while(fast.next!=null&& fast!=null){
            fast=fast.next.next;
            slow=slow.next;
            if(slow==fast){
                return true;
            }
        }
        //到这里
        return false;
    }
    public static void createLoop(MySingleLink.LinkedList head){
        MySingleLink.LinkedList cur=head;
        while(cur.next!=null){
            cur=cur.next;
        }
        cur=head.next.next;
    }
    public static void main(String[] args) {
        MySingleLink mySingleLink1=new MySingleLink();
        mySingleLink1.addFirst(12);
        mySingleLink1.addFirst(13);
        mySingleLink1.addFirst(17);
        mySingleLink1.addFirst(19);
        mySingleLink1.addFirst(20);
        mySingleLink1.addFirst(30);
        MySingleLink mySingleLink2=new MySingleLink();
        mySingleLink1.addFirst(18);
        mySingleLink1.addFirst(30);
        mySingleLink1.addFirst(40);
        mySingleLink1.addFirst(50);
        mySingleLink1.addFirst(60);
        mySingleLink1.addFirst(70);
        MySingleLink.LinkedList newHead=mergeTwoLists(mySingleLink1.head,mySingleLink2.head);
       // MySingleLink.
        createLoop(mySingleLink2.head);
        System.out.println(hasCycle(mySingleLink2.head));

    }
}
